using System;
using System.Collections.Generic;
using OrdersManager.Module.BusinessEntities;
using OrdersManager.Module.Services;

namespace OrdersManager.Module.Tests.Mocks
{
	public class MockOrderRepository : IOrderRepository
	{
		private Dictionary<Guid, Order> _orders = new Dictionary<Guid, Order>();

		public IDictionary<Guid, Order> Orders
		{
			get { return _orders; }
		}

		public void Update(Order order)
		{
			if (_orders.ContainsKey(order.Id))
			{
				_orders[order.Id] = order;
			}
		}

		public void Insert(Order order)
		{
			order.Id = Guid.NewGuid();
			_orders.Add(order.Id, order);
		}

		public Order GetById(Guid id)
		{
			if (_orders.ContainsKey(id))
				return _orders[id];
			else
				return null;
		}

		//HACK: This method was moved to Workflow + OrderService
		//public List<Order> GetOrders(OrderStateMode mode)
		//{
		//    List<Order> list = new List<Order>();
		//    foreach (Order order in _orders.Values)
		//    {
		//        //TODO: Check order state from WF service
		//        list.Add(order);
		//    }
		//    return list;
		//}

		public bool Exists(Guid id)
		{
			return _orders.ContainsKey(id);
		}
	}
}